

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class tarefas
 * @param <E>
 */
@WebServlet("/tarefasservlet")
public class tarefasservlet<E> extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public tarefasservlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub

		int i=0;
		@SuppressWarnings("unchecked")
		
		ArrayList<String> lista = (ArrayList<String>) request.getSession().getAttribute("tarefa");
		ArrayList<String> list = new ArrayList<>();
		
		String msg="";
		String tarefa = request.getParameter("tarefa");
		
		if(request.getParameter("tarefa") == null  ){
			
			msg="Digite uma Tarefa";
			return;
			
		}
		
		if(lista == null) {
		    lista = new ArrayList<String>();
		    lista.add(request.getParameter("tarefa"));
		    list.addAll(lista);
		}
		else lista.add(request.getParameter("tarefa"));
			 list.addAll(lista);
		
		
		request.getSession().setAttribute("tarefa", list);
		
		String tarefas="";
		
		for(String a : lista){
			tarefas= a;
			i++;
			request.setAttribute("indice", i);
			request.setAttribute("lista", tarefas);
		} 
				
		
		
		request.getRequestDispatcher("/tarefas.jsp").forward(request, response);
		
	}
			
	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
